/*
 * @(#)UserAddDaoImpl.java 创建于 2014年3月14日 
 * 
 * Copyright (c) 2013-2014 by Drow.  
 *
 */
package com.hangxin.basic.dao.impl;


import java.util.List;
import java.util.Map;

import org.springframework.stereotype.Repository;

import com.hangxin.basic.dao.CustomerDao;
import com.hangxin.commons.dao.impl.BasicDaoImpl;
import com.hangxin.commons.util.PageModel;

/**
 * 
 * 类名称：UserAddDaoImpl.java
 * <P/>
 * 类描述： 添加登录用户Dao接口实现类
 * <P/>
 * 创建时间：2014年3月14日
 * <P/>
 * 创建人： 段志杨
 * <P/>
 * 联系方式：315874529@qq.com
 * <P/>
 * 修改人：无
 * <P/>
 * 修改时间：无
 * <P/>
 * 修改备注：无
 * <P/>
 * 版本：v1.0
 * 
 */
@Repository
public class CustomerDaoImpl extends BasicDaoImpl implements CustomerDao
{

	@Override
	public Integer customerAdd(Object[] params)
	{
		String sql="insert into customer(code,name,taxno,addresstel,account,simno) values(?,?,?,?,?,?)";
		return this.save(sql, params);
	}

	@Override
	public PageModel customerManage(PageModel pageModel,Object[] paramscount,Object[] params)
	{
		String sqlcount="select count(*) from customer where name like ? and taxno like ? and addresstel like ? and account like ?";
		/**sqlserver版本
		String  sql="SELECT * FROM (SELECT ROW_NUMBER() OVER(order by id desc) AS rownum, * from customer  where code like ? and name like ? and taxno like ? and addresstel like ? and account like ? ) AS D WHERE rownum BETWEEN ? AND ? ";
		*/
		String  sql="SELECT  * from customer  where name like ? and taxno like ? and addresstel like ? and account like ? order by id desc limit ?,?  ";

		return this.listByObject(sqlcount, sql, pageModel, paramscount, params);
	}
	

	@Override
	public Integer  checkName(Object[] params) 
	{
		String sql="";
		if(params.length==3){
			sql="select count(*) from customer where "+params[0]+"='"+params[1]+"'"+" and id!="+params[2];
		}else{
			sql="select count(*) from customer where "+params[0]+"='"+params[1]+"'";
			
		}
		
		return this.findByCount(sql);
	}
	

	@Override
	public Map<String,Object> customerFind(Object[] params){
		String sql="select * from customer  where id=?";
		return this.findByMap(sql, params);
	}
	

	@Override
	public void customerEdit(Object[] params)
	{
		String sql="update customer set code=?,name=?,taxno=?,addresstel=?,account=?,simno=? where id=? ";
		this.update(sql, params);
	}
	
	@Override
	public List<Map<String , Object>> findCustomers(Object[] params){
		String sql="select name,taxno,addresstel,account from customer where name like ? and taxno!=''";
		return this.findMap(sql, params);
	}
	
	@Override
	public List<Map<String , Object>> findCustomer(Object[] params){
		String sql="select name,taxno,addresstel,account from customer where name = ? and taxno!=''";
		return this.findMap(sql, params);
	}
	
	@Override
	public Integer customerDel(Object[] params)
	{
		String sql="delete from customer  where id=? ";
		return this.update(sql, params);
	}
	
	@Override
	public Integer custImportSave(String[] a) {
		Object[] params= new Object[]{};
		String sql = "insert into customer(code,name,simno,taxno,addresstel,account) values "
				+ "('"+a[0]+"','"+a[1]+"','"+a[2]+"','"+a[3]+"','"+a[4]+"','"+a[5]+"')";
		return this.save(sql, params);
	}
}
